#include <fhe/core/Val.h>

namespace fhe
{
  namespace core
  {
    Val::Val()
      : data_( 0 )
    {
    }
    
    Val::Val( const Val& val )
      : data_( val.data_ ? val.data_->clone() : 0 )
    {
    }
    
    Val& Val::operator=( const Val& val )
    {
      clear();
      if ( val.data_ )
      {
        data_ = val.data_->clone();
      }
      return *this;
    }
    
    Val::~Val()
    {
      clear();
    }
    
    bool Val::empty() const
    {
      return !data_;
    }
    
    void Val::clear()
    {
      if ( data_ )
      {
        delete data_;
        data_ = 0;
      }
    }
    
    std::string Val::type() const
    {
      return data_ ? data_->typeInfo().name() : "null";
    }
    
    const std::type_info& Val::typeInfo() const
    {
      return data_ ? data_->typeInfo() : typeid(Val);
    }
  }
}
